/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine SDK - memory
// Copyright( c) 2015.  All Rights Reserved
//
// File:		AERefCounter.inl
// Author:		Gianluca Belardelli
// Date:		11/05/2015
//
/////////////////////////////////////////////////////////////////////////
#ifndef _AEREFCOUNTER_INL_
#define _AEREFCOUNTER_INL_

AE_FORCEINLINE AERefCounter::AERefCounter( void ) : m_nRefCount(0)
{
}

AE_FORCEINLINE AERefCounter::AERefCounter( const AERefCounter &originalObject ) : m_nRefCount(0) 
{
}

AE_FORCEINLINE  AERefCounter &AERefCounter::operator=( const AERefCounter &originalObject )
{
	return *this;
}

AE_FORCEINLINE AERefCounter::~AERefCounter( void )
{
	AEASSERT_MSG( m_nRefCount == 0, "Tentativo di eliminare un oggetto con contatore != 0" );
}

AE_FORCEINLINE AEINT32 AERefCounter::GetReferenceCount( void ) const
{
	return m_nRefCount;
}

AE_FORCEINLINE void AERefCounter::AddRef( void ) const
{
	AEAtomic::Increment( (AEINT32&)m_nRefCount );
}

AE_FORCEINLINE void AERefCounter::Release( void )
{
	AEASSERT( m_nRefCount > 0 );
	AEAtomic::Decrement( (AEINT32&)m_nRefCount );
	if( m_nRefCount == 0 )
		DeleteThis();
}

AE_FORCEINLINE void AERefCounter::ReleaseNoDelete( void )
{
	AEASSERT( m_nRefCount > 0 );
	AEAtomic::Decrement( (AEINT32&)m_nRefCount );
}

AE_FORCEINLINE void AERefCounter::DeleteThis( void )
{
	delete this;
	//this->operator delete( this, this );
}

#endif // _AEREFCOUNTER_INL_
